package openjdk.reflection;

import java.lang.reflect.Field;
import java.lang.reflect.Type;
import java.math.BigDecimal;

/**
 * Simple Class type
 */
public class GetGenericTypeExample {
    private int anInt;
    private BigDecimal bigNumber;

    public static void main(String... args) throws NoSuchFieldException {
        Field field = GetGenericTypeExample.class.getDeclaredField("anInt");
        Type type = field.getGenericType();
        printType(field, type);

        Field field2 = GetGenericTypeExample.class.getDeclaredField("bigNumber");
        Type type2 = field2.getGenericType();
        printType(field2, type2);
    }

    private static void printType(Field field, Type type) {
        System.out.printf("Example: %s %s;%n", field.getType().getSimpleName(), field.getName());
        System.out.println("Type class= " + type.getClass());
        System.out.println("Type name= " + type.getTypeName());
    }
}